#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool ischangestr(const string str1, const string str2, const string& s1)
{
    int j1 = 0;
    int j2 = 0;
    int oldi = 0;
    for (int i = 0; i < s1.size(); ++i)
    {
        oldi = i;
        while (str1[j1] == s1[i])
        {
            j1++;
            i++;
        }
        if (j1 == str1.size() - 1)
            return false;
        i = oldi;
        while (str2[j2] == s1[i])
        {
            j2++;
            i++;
        }
        if (j2 == str2.size() - 1)
            return true;
        i = oldi;
    }
    return false;
}
void Findstrmixed(string& s1, string& s2)
{
    string maxstr = "";
    string midstr = "";
    int flag = 1;
    if (s1.size() > s2.size())
        swap(s1, s2);
    int i = 0;
    int j = 0;
    int oldj = 0;
    while (j < s2.size())
    {
        oldj = j;
        for (i = 0; i < s1.size(); ++i)
        {
            if (s1[i] == s2[j])
            {
                midstr += s1[i];
                ++j;
            }
            else
            {
                if (maxstr.size() < midstr.size())
                    maxstr = midstr;
                if (maxstr.size() == midstr.size())
                {
                    if (ischangestr(maxstr, midstr, s1))
                        maxstr = midstr;
                }
                midstr = "";
                j = oldj;
            }
        }
        ++j;
        if ((s2.size() - j) <= maxstr.size())
            break;
    }
    cout << maxstr << endl;
}
int main()
{
    string str1;
    string str2;
    while (getline(cin, str1) && getline(cin, str2))
    {
        Findstrmixed(str1, str2);
    }
    return 0;
}